package com.yanqu.road.server.manager.activity.xingyou.inter.grid;

import com.yanqu.road.entity.activity.youxing.CrossXingYouShanShuiUserData;
import com.yanqu.road.entity.activity.youxing.ShanShuiGridParam;
import com.yanqu.road.entity.activity.youxing.config.XingYouShanShuiGridInfo;
import com.yanqu.road.logic.helper.RandomWeightConfigHelper;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.manager.activity.xingyou.DiceHandleResult;
import com.yanqu.road.server.manager.activity.xingyou.inter.GridHandleResult;
import com.yanqu.road.server.manager.activity.xingyou.inter.IXingYouGridHandler;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

/**
 * 衙门
 */
public class SecondGridHandler implements IXingYouGridHandler {

    @Override
    public void handle(XingYouShanShuiGridInfo gridInfo, int pos, int gridId, int endPos, boolean fly, DiceHandleResult result) {
        //是否停留
        boolean stop = pos == endPos;
        if(!stop){
            return;
        }
        GridHandleResult gridHandleResult = new GridHandleResult();
        CrossXingYouShanShuiUserData userData = result.getUserData();
        ShanShuiGridParam gridParam = new ShanShuiGridParam(gridId, pos, false, userData.isDrift());
        gridHandleResult.setGridParam(gridParam);

        Property fixedReward = result.getActivity().getGridInfoFixedReward(result.getUserData(), gridInfo, true);

        XingYouShanShuiProto.ShanShuiEventInfo.Builder builder = result.getActivity().getEventInfoBuilder(pos, gridId, fixedReward, false);
        builder.setFixedReward(PropertyHelper.parsePropertyToString(fixedReward));

        gridHandleResult.setBuilder(builder);
        result.getGridHandleResultList().add(gridHandleResult);

        if(userData.isDrift()) {
            //衙门直接抓捕
            result.getActivity().tryCatch(pos, result.getUserData(), result, gridHandleResult, true);
        }
    }
}
